package com.xuxueli.xxlrpc.remoting.invoker.route;


import com.xuxueli.xxlrpc.remoting.invoker.route.impl.XxlRpcLoadBalanceRandomStrategy;
import com.xuxueli.xxlrpc.remoting.invoker.route.impl.XxlRpcLoadBalanceRoundStrategy;

/**
 * @author xuxueli 2018-12-04
 */
public enum LoadBalance {

    RANDOM(new XxlRpcLoadBalanceRandomStrategy()),
    ROUND(new XxlRpcLoadBalanceRoundStrategy());


    public final XxlRpcLoadBalance xxlRpcInvokerRouter;

    private LoadBalance(XxlRpcLoadBalance xxlRpcInvokerRouter) {
        this.xxlRpcInvokerRouter = xxlRpcInvokerRouter;
    }


    public static LoadBalance match(String name, LoadBalance defaultRouter) {
        for (LoadBalance item : LoadBalance.values()) {
            if (item.name().equals(name)) {
                return item;
            }
        }
        return defaultRouter;
    }
}